package com.offcn.user.controller;

import com.offcn.dycommon.response.AppResponse;
import com.offcn.user.pojo.TMemberAddress;
import com.offcn.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: wzy
 * @Date: 2021/01/28/17:52
 * @Description:
 */
@Api(tags = "获取会员信息/更新个人信息/获取用户收获地址")
@RestController
@RequestMapping("/user")
public class UserInfoController {

    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private UserService userService;

    @ApiOperation(value = "获取用户地址")
    @GetMapping("/findAddressList")
    @ApiImplicitParam(name = "accessToken", value = "访问令牌", required = true)
    public AppResponse<List<TMemberAddress>> findAddressList(String accessToken) {
        //1.得到登录会员Id
        String memerId = redisTemplate.opsForValue().get(accessToken);
        if (StringUtils.isEmpty(memerId)) {
            return AppResponse.fail(null);
        }
        //2.查询该会员收获地址列表
        List<TMemberAddress> addressList = userService.findAddressList(Integer.parseInt(memerId));
        return AppResponse.ok(addressList);
    }

}
